<?php
/**
 * 执行提交回复相关操作
 * [ranknow bbs!] (C)2009-2015 ranknow.cn.
 *
 * @author liwei
 * @This is NOT a freeware, use is subject to license terms
 * @rcsfile $RCSfile: do_post.php,v $
 * @revision $Revision: 0.1 $
 * @date $Date: 2009/12/31 09:40:17 $
 */
require_once '../../config.inc.php';
include BBS_MDL_PATH . 'mdl_post.php';
include BBS_MDL_PATH . 'mdl_thread.php';

$action = $_GET['action']?$_GET['action']:'';
$current_time = time();
dbConnect();
$ret = 'fail';
if ( $action == 'new_post' && $_SESSION['bbs_user_id'] ) {
    $fid = $_POST['fid']?$_POST['fid']:0;
      $tid = $_POST['tid']?$_POST['tid']:0;
    $subject = $_POST['subject']?$_POST['subject']:'';
    $message = $_POST['message']?$_POST['message']:'';
      //读取主题表评论数,浏览数并更新
      $thread = get_thread_by_id( $tid );
    $data_thread = array( 'fid' => $fid,'lastpost' => $current_time,'lastposter'=>$_SESSION['bbs_username'],'replies'=>$thread['replies']+1);
    update_thread( $data_thread,$tid );
      //保存评论数据
    $data_post = array( 'tid'=>$tid, 'fid'=>$fid,'subject'=>$subject,'dateline'=>$current_time,'message'=>$message,'author'=>$_SESSION['bbs_username'],'authorid'=>$_SESSION['bbs_user_id'],'first'=>'0');
    add_post( $data_post );
    $ret = 'ok';
      if($ret=='ok'){
        set_flash('sysinfo','发布评论成功!');
      }else{
        set_flash('sysinfo','发布评论失败!');
      }
      echo $ret;
}
dbDisconnect();
?>